﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading;
using NSsh.Common.Packets;
using NSsh.Common.Utility;
using NSsh.Server.ChannelLayer;
using NSsh.Server.TransportLayer;
using NSsh.Server.TransportLayer.State;

namespace NSsh.Client {
    class Program {
        static void Main(string[] args) {
            try {
                System.Console.WriteLine("NSsh Client Console:");

                log4net.Config.XmlConfigurator.Configure();

                Dependency.RegisterSingleton<IPacketFactory, PacketFactory>("PacketFactory");
                Dependency.RegisterTransient<AbstractTransportState, ClientConnectedState>(TransportLayerState.Connected.ToString());
                Dependency.RegisterTransient<AbstractTransportState, ClientVersionsExchangedState>(TransportLayerState.VersionsExchanged.ToString());
                Dependency.RegisterTransient<AbstractTransportState, ClientKeysExchangedState>(TransportLayerState.KeysExchanged.ToString());
                Dependency.RegisterTransient<AbstractTransportState, ClientAuthenticatedState>(TransportLayerState.Authenticated.ToString());
                Dependency.RegisterSingleton<ISecureRandom, SecureRandom>("SecureRandom");
                Dependency.RegisterSingleton<ICipherFactory, CipherFactory>("CipherFactory");
                Dependency.RegisterSingleton<IMacFactory, MacFactory>("MacFactory");
                Dependency.RegisterTransient<IChannelProducer, ClientChannel>("Channel");

                TcpClient sshTCPClient = new TcpClient("127.0.0.1", 22);
                Console.WriteLine("Connected to server on " + sshTCPClient.Client.RemoteEndPoint + " from " + sshTCPClient.Client.LocalEndPoint + ".");
                TransportLayerManager clientTransportManager = new TransportLayerManager();
                clientTransportManager.Process(sshTCPClient.GetStream());

                Console.ReadLine();
            }
            catch (Exception excp) {
                Console.WriteLine("Exception Main. " + excp.Message);
            }
            finally {
                Console.WriteLine("press any key to exit...");
                Console.ReadLine();
            }
        }
    }
}
